<template>
	<view class="goods"
	@tap="
	goodDetail(
	goodsInfo.goodsId,
	goodsInfo.coupon_amount,
	goodsInfo.price,
	goodsInfo.commission_rate,
	goodsInfo.coupon_start_time,
	goodsInfo.coupon_end_time
	)">
		<image :src="getImg(goodsInfo.img)" class="good-img"></image>
		<view class="good-name">{{goodsInfo.title}}</view>
		<view class="good-shop shop2">
		<!-- 	<image src="../../static/common/taobao.png" class="good-source-icon"></image> -->
			<view class="good-shopname2"><text class="yuanjia">原价:￥{{goodsInfo.price}}</text></view>
			<view class="good-quan">￥{{goodsInfo.coupon_amount}}券</view>
		</view>
		<view class="good-price">
			<view class="after-quan">券后价￥<text class="quan-detail">{{endPrice(goodsInfo.price,goodsInfo.coupon_amount) }}</text></view>
			<!-- <view class="quan-detail">12</view> -->
			<view class="zhuang">
				<view class="coin">￥</view>
				<view class="zhuang-detail">{{ calculationRate(goodsInfo.price,goodsInfo.coupon_amount,goodsInfo.commission_rate)}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		name:"good",
		data(){
			return{
				info:"",
				yongjin:""
			}
		},
		props:{
			goodsInfo:{
				type:Object,
			}
		},
		
		methods:{
			endPrice(price,coupon_amount){
				//计算券后价
				const num = price - coupon_amount;
				if(Math.floor(num) == num){
					return num
				}else{
					return num.toFixed(2);
				}
			},
			getImg(img){//处理图片路径
				return this.$CommonJS.getBaseImgUrl(img);
			},
			goodDetail(id,coupon_amount,price,commission_rate,coupon_start_time,coupon_end_time){
				//查看商品详情
				this.$emit('goodDetail',id,coupon_amount,price,commission_rate,coupon_start_time,coupon_end_time);
			},
			calculationRateHot(tkmoney){
				//推荐商品计算佣金
				const num = tkmoney * 0.8;
				if(Math.floor(num) == num){
					this.yongjin = num;
					return num
				}else{
					this.yongjin = num.toFixed(2);
					return num.toFixed(2)
				}
				
			},
			calculation(reserve_price,coupon){
				//计算券后价
				const num = reserve_price - coupon;
				if(Math.floor(num) == num){
					return num
				}else{
					return num.toFixed(2);
				}
				
			},
			calculationRate(zk_final_price,coupon,commission_rate){
				//计算佣金分类
				//佣金 = 券后价 * 佣金比例 * 0.8
				//佣金比例 = 佣金比例/100/100
				//1.要先计算券后价
				const endPrice = zk_final_price - coupon;
				//2.计算佣金
				const num = endPrice * (commission_rate / 10000) * 0.8;
				if(Math.floor(num) == num){
					this.yongjin = num;
					return num
				}else{
					this.yongjin = num.toFixed(2);
					return num.toFixed(2)
				}
			}
		}
	}
</script>

<style>
	@import url("good.css");
	.yuanjia{
		font-size: 13px;
		color: #CCCCCC;
		text-decoration: line-through;
	}
</style>
